﻿using Fee.FileAttachs;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;

namespace JwtWebApi.Controllers
{
    [Authorize]
    [Route("[controller]")]
    [ApiController]
    [EnableCors]
    public class FileController : Controller
    {
        private readonly FileManager _fileManager;

        public FileController(FileManager fileManager)
        {
            _fileManager = fileManager;
        }

        [HttpGet("download/template")]
        public IActionResult GetBlobDownload([FromQuery] string link)
        {
            var filePath = _fileManager.GetImportTemplateFile(link);
            var contentType = "APPLICATION/octet-stream";
            var fileName = link;
            return File(System.IO.File.OpenRead(filePath), contentType, fileName);
        }
    }
}